package panels;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;

import javax.swing.ButtonGroup;
import javax.swing.JMenu;
import javax.swing.JRadioButton;

import classes.SelectionMode;

public class SelectionModeMenu extends JMenu implements ActionListener, MouseListener {

	private static final long serialVersionUID = 1L;

	private JRadioButton	selectedBtn = null;	
	private JRadioButton	buttons[] = new JRadioButton[SelectionMode.values().length];
	private	ButtonGroup	group = new ButtonGroup();
	
	public SelectionModeMenu() {
		int i;
		JRadioButton	B;
		
		for(i=0; i<SelectionMode.values().length; i++) {
			B = new JRadioButton( SelectionMode.values()[i].toString() );
			buttons[i] = B;
			if (i==0) {	
				B.setSelected(true);
				selectedBtn = B;
			} else {
				B.setSelected(false);
			}
			group.add(B);
			this.add(B);
			this.addMouseListener(this);

			B.addActionListener(this);
		}
	}

	@Override
	public void actionPerformed(ActionEvent e) {
		this.selectedBtn = (JRadioButton) e.getSource();
		this.setPopupMenuVisible(false);
		System.out.println("Selection = " + getSelection().toString());
	}
	
	public SelectionMode getSelection() {
		return SelectionMode.valueOf(this.selectedBtn.getText());
	}
	
	public void setSelected(SelectionMode M) {
		buttons[M.ordinal()].setSelected(true);
	}

	@Override
	public void mouseClicked(MouseEvent e) {	}

	@Override
	public void mousePressed(MouseEvent e) {	}

	@Override
	public void mouseReleased(MouseEvent e) {	}

	@Override
	public void mouseEntered(MouseEvent e) {	}

	@Override
	public void mouseExited(MouseEvent e) {		}

}
